<?php
namespace app\admin\controller;

use think\Db;
class Wxpage extends Base{
    public function wechat(){
        $whereAB['wx_id']=1;
        $wechatRes=Db::name('wechatconfig')->where($whereAB)->find();
        $this->assign('wechat',$wechatRes);
        if(request()->isAjax()){
            $whereID['wx_id']=1;
            $data['wx_title']=input('param.wx_title');
            $data['phone']=input('param.phone');
            $data['wx_logo']=input('param.wx_logo');
            $data['wx_qrcode']=input('param.wx_qrcode');
            $data['wx_number']=input('param.wx_number');
            $data['wx_original_id']=input('param.wx_original_id');
            $data['appid']=input('param.appid');
            $data['appsecret']=input('param.appsecret');
            $data['mch_id']=input('param.mch_id');
            $data['paykey']=input('param.paykey');
            $data['cert_p12']=input('param.cert_p12');
            $data['cert_pem']=input('param.cert_pem');
            $data['key_pem']=input('param.key_pem');
            $findres=Db::name('wechatconfig')->where($whereID)->find();
            if($findres){
                $saveres=Db::name('wechatconfig')->where($whereID)->update($data);
            }else{
                $saveres=Db::name('wechatconfig')->insert($data);
            }
            if($saveres){
                return true;
            }else{
                return false;
            }
        }
        return $this->fetch();
    }
// +-------------------------------------------------------------------------------
    public function wechaturl(){                                        //微信url配置
        $whereAB['wx_id']=1;
        $wechatRes=Db::name('wechatconfig')->where($whereAB)->find();

        $url='http://'.$_SERVER['HTTP_HOST'];
        $this->assign('url',$url);
        $this->assign('wx_original_id',$wechatRes['wx_original_id']);
        $this->assign('token',md5($wechatRes['wx_original_id']));
        return $this->fetch();

    }
    public function menu(){                                                //按钮列表
        //查询一级分类

        if(input('get.id')==null){
            $whereAA['menu_id']=0;
            $fid=0;
        }else{
            $whereAA['menu_id']=input('get.id');
            $fid=input('get.id');
        }
        $classifyRes=Db::name('menu')->where($whereAA)->order('menu_sort desc')->paginate(10,false,[
            'query' =>array ('menu_id'=>$fid)
        ]);
        $this->assign('data',$classifyRes);

        $this->assign('menu_id',$fid);

        return $this->fetch();
    }
    public function menuAdd(){
        $this->assign('menu_id',input('get.menu_id'));
        return $this->fetch();
    }
    public function menuAddFrom(){
        $post=input('post.');
        $data=[
            'menu_id'=>$post['menu_id'],
            'menu_name'=>$post['menu_name'],
            'menu_sort'=>$post['menu_sort'],
            'menu_type'=>$post['menu_type'],
            'menu_typecontent'=>$post['menu_typecontent']
        ];
        $save=Db::name('menu')->insert($data);
        if ($save){
            return true;
        }
        return array('msg'=>'提交失败！');
    }
    public function menuEdit(){
        $whereAA['id']=input('id');
        $data=Db::name('menu')->where($whereAA)->find();
        $this->assign('data',$data);
        return $this->fetch();
    }
    public function menuEditFrom(){
        $post=input('post.');
        $data=[
            'menu_name'=>$post['menu_name'],
            'menu_sort'=>$post['menu_sort'],
            'menu_type'=>$post['menu_type'],
            'menu_typecontent'=>$post['menu_typecontent']
        ];
        $whereAA['id']=$post['id'];
        $save=Db::name('menu')->where($whereAA)->update($data);
        if ($save){
            return true;
        }
        return array('msg'=>'提交失败！');
    }
    public function menuDel(){
        $post=input('post.');
        $count=count($post['data']);
        for($i=0;$i<$count;$i++){
            $whereAA['id']=$post['data'][$i];
            $del=Db::name('menu')->where($whereAA)->delete();
        }
        if($del){
            return array('msg'=>'success');
        }else{
            return array('msg'=>'error');
        }
    }
// +----------------------------------------------------------------------
    public function imgtext(){                              //图文回复页面
        $url='http://'.$_SERVER['HTTP_HOST'];
        $result=Db::name('imgtext')->paginate(10);
        $this->assign('data',$result);
        $this->assign('url',$url);
        return $this->fetch();
    }
// +----------------------------------------------------------------------
    public function imgtextAdd(){                           //添加图文回复
        return $this->fetch();
    }
    public function imgtextAddFrom(){
        $post=input('post.');
        $data=[
            't_explain'=>$post['t_explain'],
            't_title'=>$post['t_title'],
            't_img'=>$post['t_img'],
            'author'=>$post['author'],
            't_url'=>$post['t_url'],
            't_content'=>$post['t_content'],
            't_createtime'=>time(),
            't_sort'=>$post['t_sort']
        ];
        $save=Db::name('imgtext')->insert($data);
        if ($save){
            return true;
        }
        return array('msg'=>'提交失败！');
    }
// +----------------------------------------------------------------------
    public function imgtextEdit(){                        //修改图文回复
        $where['id']=input('get.id');
        $result=Db::name('imgtext')->where($where)->find();
        $this->assign('data',$result);
        return $this->fetch();
    }
    public function imgtextEditFrom(){
        $post=input('post.');
        $data=[
            't_explain'=>$post['t_explain'],
            't_title'=>$post['t_title'],
            't_img'=>$post['t_img'],
            'author'=>$post['author'],
            't_url'=>$post['t_url'],
            't_content'=>$post['t_content'],
            't_createtime'=>time(),
            't_sort'=>$post['t_sort']
        ];
        $whereAA['id']=$post['id'];
        $save=Db::name('imgtext')->where($whereAA)->update($data);
        if ($save){
            return true;
        }
        return array('msg'=>'提交失败！');
    }
// +----------------------------------------------------------------------
    public function imgtextDel(){                        //删除图文回复
        $post=input('post.');
        $count=count($post['data']);
        for($i=0;$i<$count;$i++){
            $whereAA['id']=$post['data'][$i];
            $del=Db::name('imgtext')->where($whereAA)->delete();
        }
        if($del){
            return array('msg'=>'success');
        }else{
            return array('msg'=>'error');
        }
    }
    public function reponsemsg(){
        $whereAB['re_id']=1;
        $dataRes=Db::name('reponsemsg')->where($whereAB)->find();
        $this->assign('data',$dataRes);
        if(request()->isAjax()){
            $whereID['re_id']=1;
            $data['re_title']=input('param.re_title');
            $data['re_image']=input('param.re_image');
            $data['re_url']=input('param.re_url');
            $data['re_remark']=input('param.re_remark');
            $data['re_state']=input('param.re_state');
            $findres=Db::name('reponsemsg')->where($whereID)->find();
            if($findres){
                $saveres=Db::name('reponsemsg')->where($whereID)->update($data);
            }else{
                $saveres=Db::name('reponsemsg')->insert($data);
            }
            if($saveres){
                return true;
            }else{
                return false;
            }
        }
        return $this->fetch();
    }






}